import hashlib
import os
import random
import string

def random_string():
    return ''.join(random.choices(string.ascii_letters + string.digits, k=10))

def random_md5():
    return hashlib.md5(random_string().encode('utf-8')).hexdigest()

def random_score():
    s = random.random()
    return str(round(s, 4))


def generate(size=200, file_max=20, file_prefix='data/random-'):
    os.makedirs(os.path.dirname(file_prefix), exist_ok=True)
    f = None
    file_cnt = 0
    line_cnt = 0
    while True:
        if line_cnt % file_max == 0:
            if f:
                f.close()
            f = open(f'{file_prefix}device-{file_cnt:02d}.txt', 'w')
            file_cnt += 1
        device = random_md5()
        score_cnt = random.randint(1, 8)
        for j in range(score_cnt):
            score = random_score()
            f.write(f"{device},{j},{score}\n")
            line_cnt += 1
            if line_cnt % file_max == 0:
                break
        if line_cnt >= size:
            break
    f.close()

if __name__ == '__main__':
    # generate(200, 20)
    generate(20000000, 2000000)